#ifndef BASE_SYSTEM_LOG_LOGGER_INCLUDE_LOG_STREAM_H
#define BASE_SYSTEM_LOG_LOGGER_INCLUDE_LOG_STREAM_H

#include "fixed_buffer.h"
#include "log_level.h"
#include "system_log_config.h"

namespace Base {
namespace SystemLog {
class LogFormatter;
class LogFormat;
class LogStream {
    using Buffer = FixedBuffer<DEFAULT_BUFFER_SIZE>;

public:
    LogStream(LogLevel level, const char* file, int line);
    ~LogStream();

    // 禁用拷贝和移动
    LogStream(const LogStream &) = delete;
    LogStream& operator=(const LogStream &) = delete;

    // 运算符重载
    LogStream &operator<<(bool value);
    LogStream &operator<<(short value);
    LogStream &operator<<(unsigned short value);
    LogStream &operator<<(int value);
    LogStream &operator<<(unsigned int value);
    LogStream &operator<<(long value);
    LogStream &operator<<(unsigned long value);
    LogStream &operator<<(long long value);
    LogStream &operator<<(unsigned long long value);
    LogStream &operator<<(float value);
    LogStream &operator<<(double value);
    LogStream &operator<<(long double value);
    LogStream &operator<<(char value);
    LogStream &operator<<(const char* value);
    LogStream &operator<<(const std::string &value);
    LogStream &operator<<(const void* value);

    // 自定义格式化
    LogStream &operator<<(const LogFormatter &formatter);
    LogStream& operator<<(const LogFormat &format);

    // 获取缓冲区内容
    const Buffer &GetBuffer() const {
        return buffer_;
    }

    // 获取日志级别
    LogLevel GetLogLevel() const {
        return level_;
    }

    // 获取源码位置
    const char* GetFile() const {
        return file_;
    }
    int32_t GetLine() const {
        return line_;
    }

    // 手动刷新
    void Flush();

private:
    template <typename T>
    void FormatInteger(T value);

    Buffer buffer_;
    LogLevel level_;
    const char* file_;
    int32_t line_;
};
} // namespace SystemLog
} // namespace Base

#endif // BASE_SYSTEM_LOG_LOGGER_INCLUDE_LOG_STREAM_H